package com.zte.moon.yutu;

import java.util.LinkedList;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-1-5
 * Time: 下午8:52
 * To change this template use File | Settings | File Templates.
 */
public class ControlCenter {

    //类与类之间的交互，传参 or 私有
    public void setArea(String str, Area area) {
        String[] strArray = str.split(" ");
        Point point1 = new Point(Integer.parseInt(strArray[0]),Integer.parseInt(strArray[1]));
        Point point2 = new Point(Integer.parseInt(strArray[2]),Integer.parseInt(strArray[3]));
        area.setPoint(point1, point2);
    }


    public void loadDetector(String str, Detector detector, Area area) {
        String[] strArray = str.split(" ");
        Point point = new Point(Integer.parseInt(strArray[0]), Integer.parseInt(strArray[1]));

        detector.load(point, Direction.valueof(strArray[2]), area);
    }

    public void sendCommand(String strCommand, Detector detector) {
        LinkedList<Command> commandList = new LinkedList<Command>();
        //SB java split 突出一个坑多，SB
        String[] strArray = strCommand.split("|");
        for (int i = 0; i < strArray.length; i++){
            if (strArray[i].equals(""))
                continue;
            commandList.add(Command.valueof(strArray[i]));
        }

        detector.takeAction(commandList);
    }

    public void setSensor(Detector detector, Sensor sensor) {
        detector.setSensor(sensor);
    }

    public void findPits(Detector detector) {
        detector.findPits();
    }
}
